package utils

import (
	"fmt"
	"log"
	"os"
	"time"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var (
	DB *gorm.DB
)

func InitMySQL() {
	newLogger := logger.New(
		// 自定义日志模板 打印sql语句
		log.New(os.Stdout, "\r\n", log.LstdFlags),
		logger.Config{
			SlowThreshold: time.Second, // 慢 SQL 阈值
			LogLevel:      logger.Info, // 日志级别
			Colorful:      true,        // 彩色打印
		},
	)
	dsn := "root:Zxw.951212@tcp(43.138.27.18:3306)/user_basic?charset=utf8mb4&parseTime=True&loc=Local"
	DB, _ = gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: newLogger})

	fmt.Println("mysql inited")
	// user := models.UserBasic{}
	// DB.Find(user)
	// fmt.Println(user)
	// return DB
}
